<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<include file="Widget/head" />
	<link rel="stylesheet" href="__PUBLIC__/kindeditor-4.1.10/themes/default/default.css" />
	<script charset="utf-8" src="__PUBLIC__/kindeditor-4.1.10/kindeditor-min.js"></script>
	<script charset="utf-8" src="__PUBLIC__/kindeditor-4.1.10/lang/zh_CN.js"></script>
	<script type="text/javascript">
	var queryParams = {ajax:'y',cid:"{$cate}"};
	var myeditor;
	$(function(){
		var tb_search = document.getElementById('tb_search');
		queryParams.keyword = tb_search.keyword.value;
		$('#dg').datagrid({
			iconCls: 'icon-save',
			singleSelect: true,
			pagination:true,
			cache:false,
			method:'get',
			url: "{:U('lists')}" ,
			columns:[[
					{field:'account',title:'商家用户名',width:150,align:'center',halign:'center'},
					{field:'realname',title:'真实姓名',width:70,align:'center',halign:'center'},
					{field:'idcard',title:'身份证号',width:150,align:'center',halign:'center'},
					{field:'able_money',title:'可用余额',width:70,align:'center',halign:'center'},
					{field:'ice_money',title:'冻结余额',width:70,align:'center',halign:'center'},
					{field:'total_money',title:'账户余额',width:70,align:'center',halign:'center'},
					{field:'time_type',title:'注册日期',width:130,align:'center',halign:'center'},
					{field:'status',title:'审核',width:50,align:'center',halign:'center',
						formatter:function(value,row,index){
							if (value>0) {
								return '<span class="diyico icon-ok">&nbsp;</span>';
							}else {
								return '<a href="javascript:void(0)" onclick="state('+row.id+')"><span class="diyico icon-disable">&nbsp;</span></a>';
							}
						}
					},
					{field:'zhengmian',title:'身份证正面图',width:100,align:'center',halign:'center',
						formatter:function(value,row,index){
							if (value) return '<a href="'+value+'" target="_blank"><img src="'+value+'" width="80px" height="60px" /></a>';
							else return '<img src="__IMG__/nopic.jpg" width="80px" height="60px" />';
						}
					},
					{field:'beimian',title:'身份证背面图',width:100,align:'center',halign:'center',
						formatter:function(value,row,index){
							if (value) return '<a href="'+value+'" target="_blank"><img src="'+value+'" width="80px" height="60px" /></a>';
							else return '<img src="__IMG__/nopic.jpg" width="80px" height="60px" />';
						}
					},
					{field:'bili',title:'返现比例',width:50,align:'center',halign:'center'},
			]],
			queryParams: queryParams,
			pageSize: {$_rows} ,
			pageNumber: {$_page},
			toolbar: '#tb',
			onDblClickRow: function() {
				editRow();
			}
		});
		var pager = $('#dg').datagrid('getPager');//分页对象
		pager.pagination({
			displayMsg:''
		});
	});
	//状态切换
	function state(id) {
		$('#dg').datagrid('loading');
		$.ajax({
			cache: false,
			type: "post",
			url: "{:U('state')}",
			data: {id:id},
			async: true, //同步请求, 其它操作必须等待请求完成才可以执行
			success: function(dd) {
				$('#dg').datagrid('reload');
				//$('#dg').datagrid('loaded');
			}
		});
	}
	//编辑记录
	function editRow() {
		var row = $('#dg').datagrid('getSelected');
		//alert(JSON.stringify(row));
		if (row){
			$('#formRow').form('load',row);
			$("#editRow").dialog({
				width: 300,
				title: row.account,
				iconCls: "icon-save",
				cache: false,
				modal: true,
				buttons:[{
					iconCls: 'icon-save',
					text: "修改保存",
					handler:function(){
						$('#formRow').form('submit',{
							url: "{:U('update')}",
							onSubmit: function(param){
								if ($(this).form('validate')) {
									$("body").easyMask('show');
									param.id = row.id;
								}else return false;
							},
							success: function(dd) {
								$('#dg').datagrid('reload');
								$("body").easyMask('hide');
								dd = eval('(' + dd + ')');
								if (dd.status>0) {
									$.messager.alert('',dd.info,'info');
									$("#editRow").dialog('close');
								}else $.messager.alert('',dd.info,'error');
							}
						});
					}
				},{
					iconCls: 'icon-cancel',
					text: "关闭",
					handler:function(){
						$("#editRow").dialog('close');
					}
				}],
				onBeforeClose:function(){
					KindEditor.remove('#editor_content');
				}
			});
		}
	}
	//筛选查询
	function gosearch() {
		$('#tb_search').form('submit',{
			queryParams: {ajax:'y',cid:"{$cate}"},
			onSubmit:function(){
				//做数据处理
				queryParams.keyword = this.keyword.value;
				$('#dg').datagrid('load',queryParams);
				return false;
			}
		});
	}
	function goclear() {
		$('#tb_search').form('clear');
		queryParams = {ajax:'y',cid:"{$cate}"};
	}
	//删除记录
	function delRow() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.messager.confirm('', '确认删除此条信息吗?', function(r) {
				if (r){
					$("body").easyMask('show');
					$.ajax({
						cache: false,
						type: "post",
						url: "{:U('delete')}",
						data: {id:row.id},
						async: true, //同步请求, 其它操作必须等待请求完成才可以执行
						success: function(dd) {
							$('#dg').datagrid('reload');
							$("body").easyMask('hide');
							$.messager.alert('',dd.info,'info');
						},
						error: function() {
							$("body").easyMask('hide');
						}
					});
				}
			});
		}
	}
	//增加记录
	function addRow(){
		var row = $('#dg').datagrid('getSelected');
		$("#editRow").dialog({
			width: 300,
			title: "新增商家用户",
			iconCls: "icon-add",
			cache: false,
			modal: true,
			buttons:[{
				iconCls: 'icon-add',
				text: "新增保存",
				handler:function(){
					$('#formRow').form('submit',{
						url: "{:U('insert')}",
						onSubmit: function(param){
							if ($(this).form('validate')) {
								$("body").easyMask('show');
								param.cate = "{$cate}";
							}else {
								return false;
							}
						},
						success: function(dd) {
							$('#dg').datagrid('reload');
							$("body").easyMask('hide');
							dd = eval('(' + dd + ')');
							if (dd.status>0) {
								$.messager.alert('',dd.info,'info');
								$("#editRow").dialog('close');
							}else {
								$.messager.alert('',dd.info,'error');
							}
						}
					});
				}
			},{
				iconCls: 'icon-cancel',
				text: "关闭",
				handler:function(){
					$("#editRow").dialog('close');
				}
			}],
			onClose: function(){
				$('#formRow').form('clear');
			}
		});
	}
	</script>
</head>

<body class="easyui-layout">
<table id="dg" title="" style="width:100%;height:100%" border="0"></table>

<div id="tb" class="datagrid-toolbar">
	<form id="tb_search" method="get">
	<table cellspacing="0" cellpadding="3">
	<tr>
		<td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" onclick="editRow();">查看编辑</a></td>
		<td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" onclick="delRow();">删除</a></td>
		<td><span class="datagrid-btn-separator"></span></td>
		<td>关键字: <input name="keyword" class="easyui-textbox" style="width:100px" value="{$keyword}"></td>
		<td>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="gosearch()">搜索</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" onclick="goclear()">清空</a>
		</td>
	</tr>
	</table>
	</form>
</div>

<div id="editRow">
<form id="formRow" method="post" enctype="multipart/form-data">
	<table cellspacing="0" cellpadding="3">
		<tr>
			<td>用户名:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="account" readonly></td>
		</tr>
		<tr>	
			<td>真实姓名:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="realname" readonly></td>
		</tr>	
		<tr>
			<td>身份证号:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="idcard" readonly></td>
		</tr>
		<tr>	
			<td>邮箱:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="email" readonly></td>
		</tr>
		<tr>	
			<td>qq:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="qq" readonly></td>
		</tr>
		<tr>	
			<td>可用余额:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="able_money" readonly></td>
		</tr>
		<tr>	
			<td>冻结金额:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="ice_money" readonly></td>
		</tr>
		<tr>	
			<td>账户总额:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="total_money" readonly></td>
		</tr>
		<tr>	
			<td>注册时间:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="time_type" readonly></td>
		</tr>
		<tr>	
			<td>返现比例:</td>
			<td><input class="easyui-textbox" style="width:200;" type="text" name="bili" ></td>
		</tr>
	</table>
</form>
</div>
</body>
</html>